package hr.riteh.assistivecommunicator;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class CategorySentencesActivity extends Activity implements AdapterView.OnItemClickListener
{
	// Key names for extra intent data
	private static final String EXTRA_CATEGORY = "category_id";

	public static void start(Context context, long category_id)
	{
		Intent intent = new Intent(context, CategorySentencesActivity.class);
		intent.putExtra(EXTRA_CATEGORY, category_id);
		context.startActivity(intent);
	}

	private Database mDatabase = new Database(this);

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		long category_id = getIntent().getLongExtra(EXTRA_CATEGORY, 0);

		SentencesAdapter adapter = new SentencesAdapter(mDatabase.getCategorySentences(category_id));

		ListView listview = new ListView(this);
		listview.setAdapter(adapter);
		listview.setOnItemClickListener(this);

		setContentView(listview);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	{
		mDatabase.increaseSentenceUsage(id);
	}
}
